Skip to content

Conversation

Siddharthgolecha
Copy link

@Siddharthgolecha Siddharthgolecha commented Aug 7, 2025

Summary

Qiskit Machine Learning library currently uses Qiskit >=1.0 and <2.0 making it incompatible with the latest Qiskit Version and changes. I have attempted to migrate the library to use the latest Qiskit version.

Fixes #897
Fixes #934
Fixes #975

🤖 ✨ Made with the help of the Qiskit Code Assistant

Details and comments

  1. Migrated the usage of
  • qiskit.primitives.BaseSampler to qiskit.primitives.BaseSamplerV2
  • qiskit.primitives.BaseSamplerV1 to qiskit.primitives.BaseSamplerV2
  • qiskit.primitives.Sampler to qiskit.primitives.StatevectorSampler
  • qiskit.primitives.BaseEstimator to qiskit.primitives.BaseEstimatorV2
  • qiskit.primitives.BaseEstimatorV1 to qiskit.primitives.BaseEstimatorV2
  • qiskit.primitives.Estimator to qiskit.primitives.StatevectorEstimator
  • qiskit.circuit.library.ZZFeatureMap to qiskit.circuit.library.zz_feature_map
  • qiskit.circuit.library.ZFeatureMap to qiskit.circuit.library.z_feature_map
  • qiskit.circuit.library.RealAmplitudes to qiskit.circuit.library.real_amplitudes
  • qiskit.circuit.library.EfficientSU2 to qiskit.circuit.library.efficient_su2
  • qiskit.circuit.library.PauliFeatureMap to qiskit.circuit.library.pauli_feature_map
  1. Corrected the test cases to incorporate these new changes.
  2. Fixed the new usage and signatures to match Qiskit's latest practices.
  3. Removed the argument use_methods=True in VQC as it is not required anymore.

@CLAassistant
Copy link

CLAassistant commented Aug 7, 2025

CLA assistant check
All committers have signed the CLA.

@woodsp-ibm
Copy link
Member

woodsp-ibm commented Aug 7, 2025

An overall comment. The V1 primitives usage was deprecated in 0.8 release and marked for removal in 0.9. So in that regards that aspect of this PR fits with the plan as the next main release to happen would be 0.9. However the removal of the Blueprint circuit support - this was deprecated in this PR #945 which was intended to go out in 0.9 with the removal in a subsequent version. Qiskit has deprecated these Blueprint based circuits with the plan to remove them in 0.3 3.0. So they do not need removing to support 0.2 2.0 indeed removing them, without even having released 0.9 with them being deprecated (as done in #945) would be a breaking change for end-users with no notice at all. Hence that aspect of this PR is really too soon.

@Siddharthgolecha
Copy link
Author

So they do not need removing to support 0.2 indeed removing them, without even having released 0.9 with them being deprecated (as done in #945) would be a breaking change for end-users with no notice at all. Hence that aspect of this PR is really too soon.

Hi, do you mean that since BlueprintCircuit is just deprecated in the 2.1 and will be removed completely in 3.0, we should not remove it or its related components? Like ZZFeatureMap and RealAmplitudes?

@woodsp-ibm
Copy link
Member

Hi, do you mean that since BlueprintCircuit is just deprecated in the 2.1 and will be removed completely in 3.0, we should not remove it or its related components? Like ZZFeatureMap and RealAmplitudes?

Yes they were deprecated in Qiskit 2.0 and planned to be removed in 3.0 (my bad I typed 0.2 and 0.3 above - I edited the original comment. As ML has not been released with the update that deprecates their use itself we do not want to remove Blueprint circuits from being used at this time - rather in a future version to allow users to change/update any existing code they may have that uses these rather than it just breaking if their support was removed. The next version of ML to be released, i.e. 0.9, would include their deprecation as was added by #945. So far that code only exists here in the repo until such time as a new release is made that includes it in the official version (i.e 0,9). Is that clearer. Removing the V1 primitive support is ok, V2 support was added in the last release (0,8) so both were supported by ML but V1 usage was deprecated - giving time for people to switch their code to V2. So the plan was to remove V1 support for the 0.9 release. So you see the pattern, support both old way, but deprecated, and the new way for a period of time to allow users time to changeover without breaking their code,

@Siddharthgolecha
Copy link
Author

As ML has not been released with the update that deprecates their use itself we do not want to remove Blueprint circuits from being used at this time - rather in a future version to allow users to change/update any existing code they may have that uses these rather than it just breaking if their support was removed.

I agree, we don't want to break the user experience for the users. But what I am trying to say is that even if we remove these, it won't break the user experience. Let's take one example, the function utils.adjust_num_qubits.derive_num_qubits_feature_map_ansatz takes in num_qubits, feature_map, ansatz and use_methods as parameters. I have simplified the logic by removing the use_methods and usage of BlueCircuit derived classes. But I have not removed BlueCircuit usage completely. The QNNCircuit class still exists and I have not made any change to that. So, I think the changes I have made regarding that do not impact the user experience and the code. However, I would like to hear your thoughts on this as well.

@Siddharthgolecha
Copy link
Author

Hey @woodsp-ibm , is there any blocking issue?

OkuyanBoga
OkuyanBoga previously approved these changes Sep 3, 2025
Copy link
Collaborator

@OkuyanBoga OkuyanBoga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall lgtm. However, some test cases needs to be cleaned up before 0.9.

I think it is ready when the errors are fixed for the unittests.

@OkuyanBoga OkuyanBoga self-requested a review September 3, 2025 11:11
@edoaltamura edoaltamura added this to the v.0.9.0 milestone Sep 4, 2025
@edoaltamura edoaltamura added the type: epic 😎 A theme of work that contain sub-tasks label Sep 4, 2025
@Siddharthgolecha
Copy link
Author

Overall lgtm. However, some test cases needs to be cleaned up before 0.9.

I think it is ready when the errors are fixed for the unittests.

Thanks for quite the fixup. I guess QCA removed quite a lot of copyright comments. Anyways, I'll start working on the test cases which are failing

@edoaltamura
Copy link
Collaborator

A recurring error so far is the following:

circuit_key = hash(circuit)
                  ^^^^^^^^^^^^^
TypeError: unhashable type: 'QuantumCircuit'

with qiskit==2.1.2

@edoaltamura
Copy link
Collaborator

And also clashed between Class and Method definitions of circuits (cfr BlueprintCircuit):

  File "/qiskit-machine-learning-Siddharthgolecha/test/circuit/library/test_qnn_circuit.py", line 97, in test_construction_before_build

AssertionError: <class 'qiskit.circuit.quantumcircuit.QuantumCircuit'> != <function zz_feature_map at 0x107740400>

@edoaltamura
Copy link
Collaborator

Also the Readme example seems to need tweaking...
test_readme_sample.py", line 78, in test_readme_sample
self.assertGreater(score, 0.7)
AssertionError: 0.5 not greater than 0.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: epic 😎 A theme of work that contain sub-tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type hints modernization Remove primitives V1 Migration to qiskit 2.0 and integration testing
5 participants